package book.zone.filter;

import book.zone.log.Logger;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: ndemeshchenko
 * Date: May 14, 2010
 * Time: 11:08:30 AM
 */
public class TimeFilter implements Filter {
    FilterConfig filterConfig;

    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest hServletRequest = (HttpServletRequest)servletRequest;
        String uri =hServletRequest.getRequestURI();
        long befor = System.currentTimeMillis();
        filterChain.doFilter(servletRequest, servletResponse);
        long after = System.currentTimeMillis();
        Logger.out(uri + " : " + (after - befor)+ "ms;");
    }

    public void destroy() {
    }
}
